<?php
namespace App\Models;
use Illuminate\Http\Request;
use DB;



/**
 * 管理员模型类
 */
class Project_admin_user_role extends BaseModel
{

    public $table = "project_admin_user_role";    //指定表名

    /**
     * 获取用户的角色
     * @param $uid
     * @return array
     */
    public  static function getRole($uid)
    {
        $userRole = DB::table("project_admin_user_role")->where("uid",$uid)->lists("rid");
        return $userRole;
    }

    /**
     * @param $request
     * @return mixed
     */
    public  static  function distRole($request)
    {
        DB::table('project_admin_user_role')->where('uid',$request->uid)->delete(); //删除用户的以前角色

         if(!empty($request->userRole)) {
             $role = [];                             //处理添加数据
             foreach ($request->userRole as $k => $v) {
                 $role[] = ['uid' => $request->uid, 'rid' => $v];
             }
         }
        $true = DB::table('project_admin_user_role')->insert($role);

        return $true;
    }
}